package com.Txunda.fxw.ui.base;

import java.util.ArrayList;
import java.util.List;

import com.Txunda.fxw.ui.toolkit.util.TTSController;
import com.amap.api.navi.AMapNavi;
import com.amap.api.navi.AMapNaviListener;
import com.amap.api.navi.AMapNaviView;
import com.amap.api.navi.AMapNaviViewListener;
import com.amap.api.navi.model.AMapLaneInfo;
import com.amap.api.navi.model.AMapNaviCross;
import com.amap.api.navi.model.AMapNaviInfo;
import com.amap.api.navi.model.AMapNaviLocation;
import com.amap.api.navi.model.AMapNaviStaticInfo;
import com.amap.api.navi.model.AMapNaviTrafficFacilityInfo;
import com.amap.api.navi.model.AimLessModeCongestionInfo;
import com.amap.api.navi.model.AimLessModeStat;
import com.amap.api.navi.model.NaviInfo;
import com.amap.api.navi.model.NaviLatLng;
import com.autonavi.tbt.NaviStaticInfo;
import com.autonavi.tbt.TrafficFacilityInfo;

import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

public abstract class BaseActivity extends BaseAty implements AMapNaviListener, AMapNaviViewListener {

	protected AMapNaviView mAMapNaviView;
	protected AMapNavi mAMapNavi;
	protected TTSController mTtsManager;
	protected NaviLatLng mEndLatlng = new NaviLatLng(39.825846, 117.432765);
	protected NaviLatLng mStartLatlng = new NaviLatLng(39.925041, 116.437901);
	protected final List<NaviLatLng> sList = new ArrayList<NaviLatLng>();
	protected final List<NaviLatLng> eList = new ArrayList<NaviLatLng>();
	protected List<NaviLatLng> mWayPointList;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// ʵ������������
		mTtsManager = TTSController.getInstance(getApplicationContext());
		mTtsManager.init();

		//

		mAMapNavi = AMapNavi.getInstance(getApplicationContext());
		mAMapNavi.addAMapNaviListener(this);
		mAMapNavi.addAMapNaviListener(mTtsManager);
		// ����ģ�⵼�����г��ٶ�
		mAMapNavi.setEmulatorNaviSpeed(75);



		sList.add(mStartLatlng);
		eList.add(mEndLatlng);
	}

	@Override
	protected void onResume() {
		super.onResume();
		mAMapNaviView.onResume();
	}

	@Override
	protected void onPause() {
		super.onPause();
		mAMapNaviView.onPause();

		// ������ֹͣ�㵱ǰ��˵����仰��һ�ᵽ�µ�·�ڻ��ǻ���˵��
		mTtsManager.stopSpeaking();
		//
		// ֹͣ����֮�󣬻ᴥ���ײ�stop��Ȼ��Ͳ������лص��ˣ�����Ѷ�ɵ�ǰ����û��˵��İ�仰���ǻ�˵��
		// mAMapNavi.stopNavi();
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		mAMapNaviView.onDestroy();
		// since 1.6.0 ������naviview destroy��ʱ���Զ�ִ��AMapNavi.stopNavi();������ִ��
		mAMapNavi.stopNavi();
		mAMapNavi.destroy();
		mTtsManager.destroy();
	}

	@Override
	public void onInitNaviFailure() {
		Toast.makeText(this, "init navi Failed", Toast.LENGTH_SHORT).show();
	}

	@Override
	public void onInitNaviSuccess() {
		// 初始化成�?
	}

	@Override
	public void onStartNavi(int type) {
		// �?始导航回�?
	}

	@Override
	public void onTrafficStatusUpdate() {
		//
	}

	@Override
	public void onLocationChange(AMapNaviLocation location) {
		// 当前位置回调
	}

	@Override
	public void onGetNavigationText(int type, String text) {
		// 播报类型和播报文字回�?
	}

	@Override
	public void onEndEmulatorNavi() {
		// 结束模拟导航
	}

	@Override
	public void onArriveDestination() {
		// 到达目的�?
	}

	@Override
	public void onArriveDestination(NaviStaticInfo naviStaticInfo) {
		// 到达目的地，有统计信息回�?
	}

	@Override
	public void onArriveDestination(AMapNaviStaticInfo aMapNaviStaticInfo) {

	}

	@Override
	public void onCalculateRouteSuccess() {
		// 路线计算成功
	}

	@Override
	public void onCalculateRouteFailure(int errorInfo) {
		// 路线计算失败
		Log.e("dm", "--------------------------------------------");

		Log.i("dm", "错误码详细链接见：http://lbs.amap.com/api/android-navi-sdk/guide/tools/errorcode/");
		Log.e("dm", "--------------------------------------------");

	}

	@Override
	public void onReCalculateRouteForYaw() {
		// 偏航后重新计算路线回�?
	}

	@Override
	public void onReCalculateRouteForTrafficJam() {
		// 拥堵后重新计算路线回�?
	}

	@Override
	public void onArrivedWayPoint(int wayID) {
		// 到达途径�?
	}

	@Override
	public void onGpsOpenStatus(boolean enabled) {
		// GPS�?关状态回�?
	}

	@Override
	public void onNaviSetting() {
		// 底部导航设置点击回调
	}

	@Override
	public void onNaviMapMode(int isLock) {
		// 地图的模式，锁屏或锁�?
	}

	@Override
	public void onNaviCancel() {
		finish();
	}

	@Override
	public void onNaviTurnClick() {
		// 转弯view的点击回�?
	}

	@Override
	public void onNextRoadClick() {
		// 下一个道路View点击回调
	}

	@Override
	public void onScanViewButtonClick() {
		// 全览按钮点击回调
	}

	@Deprecated
	@Override
	public void onNaviInfoUpdated(AMapNaviInfo naviInfo) {
		// 过时
	}

	@Override
	public void onNaviInfoUpdate(NaviInfo naviinfo) {
		// 导航过程中的信息更新，请看NaviInfo的具体说�?
	}

	@Override
	public void OnUpdateTrafficFacility(TrafficFacilityInfo trafficFacilityInfo) {
		// 已过�?
	}

	@Override
	public void OnUpdateTrafficFacility(AMapNaviTrafficFacilityInfo aMapNaviTrafficFacilityInfo) {
		// 已过�?
	}

	@Override
	public void showCross(AMapNaviCross aMapNaviCross) {
		// 显示转弯回调
	}

	@Override
	public void hideCross() {
		// 隐藏转弯回调
	}

	@Override
	public void showLaneInfo(AMapLaneInfo[] laneInfos, byte[] laneBackgroundInfo, byte[] laneRecommendedInfo) {
		// 显示车道信息

	}

	@Override
	public void hideLaneInfo() {
		// 隐藏车道信息
	}

	@Override
	public void onCalculateMultipleRoutesSuccess(int[] ints) {
		// 多路径算路成功回�?
	}

	@Override
	public void notifyParallelRoad(int i) {
		if (i == 0) {
			Toast.makeText(this, "当前在主辅路过渡", Toast.LENGTH_SHORT).show();
			Log.d("wlx", "当前在主辅路过渡");
			return;
		}
		if (i == 1) {
			Toast.makeText(this, "当前在主�?", Toast.LENGTH_SHORT).show();

			Log.d("wlx", "当前在主�?");
			return;
		}
		if (i == 2) {
			Toast.makeText(this, "当前在辅�?", Toast.LENGTH_SHORT).show();

			Log.d("wlx", "当前在辅�?");
		}
	}

	@Override
	public void OnUpdateTrafficFacility(AMapNaviTrafficFacilityInfo[] aMapNaviTrafficFacilityInfos) {
		// 更新交�?�设施信�?
	}

	@Override
	public void updateAimlessModeStatistics(AimLessModeStat aimLessModeStat) {
		// 更新巡航模式的统计信�?
	}

	@Override
	public void updateAimlessModeCongestionInfo(AimLessModeCongestionInfo aimLessModeCongestionInfo) {
		// 更新巡航模式的拥堵信�?
	}

	@Override
	public void onLockMap(boolean isLock) {
		// 锁地图状态发生变化时回调
	}

	@Override
	public void onNaviViewLoaded() {
		Log.d("wlx", "导航页面加载成功");
		Log.d("wlx", "请不要使用AMapNaviView.getMap().setOnMapLoadedListener();会overwrite导航SDK内部画线逻辑");
	}

	@Override
	public boolean onNaviBackClick() {
		return false;
	}

}
